﻿@model SysUser
@{
    ViewBag.Title = "用户信息";
    Layout = "~/Views/Shared/_EasyUILayout.cshtml";
}
<script src="~/scripts/jquery.uploader.min.js" type="text/javascript"></script>
<script type="text/javascript">
    var id = '@Request.QueryString["id"]';
    var orgId = '';
    var post = '';

    $(function () {
        loadInfo();
        initUploader();
    });

    //加载机构
    function loadOrgs() {
        $('#cboOrgID').combotree({
            url: "@Url.Action("Data", "Org")?targetId=" + orgId + '&flag=3',
            onLoadSuccess: function () {
                if (orgId != '' && orgId != null) {
                    $('#cboOrgID').combotree('setValue', orgId);
                }
            },
            onSelect: function (row) {
                orgId = row.id;
                loadPost();
            }
        });
    }

    function loadPost() {
        $('#cboPost').combobox({
            url: "@Url.Action("DataByAssign", "OrgPost")?orgId=" + orgId + '&flag=3',
            valueField: 'PostID',
            textField: 'Name',
            onLoadSuccess: function () {
                if (post != '' && post != null) {
                    $('#cboPost').combobox('setValues', post);
                }
            }
        });
    }

    //加载信息
    function loadInfo() {
        if (id !== '') {
            $.getJSON('@Url.Action("Get")?id=' + id, function (data) {
                common.processResult(data, function () {
                    $('#form1').form('load', data);
                    orgId = data.OrgID;
                    post = data.Post;
                    if (data.Photo != '') {
                        $('#photo').attr('src', '../../' + data.Photo);
                        $('#photo').attr('file', data.Photo);
                    }
                    loadOrgs();
                    loadPost();
                });
            });

            $('#btnSaveAndNew').remove();
        }
        else {
            loadOrgs();
        }
    }

    //初始化上传插件
    function initUploader() {
        $('.uploader').upload({
            extFilter: 'png;jpg;jpeg;gif',
            action: '@Url.Action("UploadPhoto")?userId=' + id,
            useHttpModule: false,
            onFileExtError: function () {
                common.alert('只允许上传png、jpg、jpeg、gif类型的文件。');
            },
            onComplete: function (result, index, ele) {
                $('#photo').attr('src', "../../" + result);
                $('#photo').attr('file', result);
            }
        });
    }

    //保存信息
    function saveInfo(isNew) {
        if (!$('#form1').form('validate')) {
            return;
        }

        var postData = new Object();

        //将表单填充的内容序列化为json
        var data = $('#form1').form('save');
        postData["info"] = JSON.stringify(data);
        common.antiToken(postData);

        common.showProcess();
        $.post('@Url.Action("Save")?id=' + id, postData, function (result) {
            common.processResult(result, function () {
                if (isNew) {
                    $('#form1').form('clear');
                }

                common.setReturnValue(true);

                if (common.closeWhenSave && !isNew) {
                    common.closeWindow();
                }
            });
        });
    }

</script>
@Html.AntiForgeryToken()
<div data-options="region:'center',border:false">
    <table class="form-body">

        <tr>
            <td class="addon">帐号</td>
            <td>@Html.TextBox(s => s.Account, new TextBoxSettings { Readonly = true, Editable = false }).Style("width:200px")</td>
            <td rowspan="4" style="padding-left:20px;vertical-align:top;text-align:center">
                <img id="photo" src="~/content/images/photo.png" style="width:120px;height:140px" /><br />
                <a class="uploader">上传头像</a>
            </td>
        </tr>
        <tr>
            <td class="addon">姓名</td>
            <td>@Html.TextBox(s => s.Name).Style("width:200px")</td>
        </tr>
        <tr>
            <td class="addon">身份证号</td>
            <td>@Html.TextBox(s => s.IDCard).Style("width:200px")</td>
        </tr>
        <tr>
            <td class="addon">所属部门</td>
            <td>@Html.ComboTree(s => s.OrgID, new ComboTreeSettings { PanelHeight = 400, PanelWidth = 300 }).MarkNoClear().Style("width:200px")</td>
        </tr>
        <tr>
            <td class="addon">性别</td>
            <td>@Html.ComboBox(s => s.Sex, typeof(Sex), new ComboBoxSettings { Value = "0" }).Style("width:200px").MarkNoClear()</td>
        </tr>
        @*<tr>
                <td class="addon">学历</td>
                <td>@Html.ComboBox(s => s.DegreeNo, new ComboBoxSettings { Url = Url.BindDict(DicName.Degree, flag: ItemFlag.Select).ToString(), ValueField = "id", TextField = "text" }).Style("width:200px")</td>
            </tr>
            <tr>
                <td class="addon">职称</td>
                <td>@Html.ComboBox(s => s.TitleNo, new ComboBoxSettings { Url = Url.BindDict(DicName.Title, flag: ItemFlag.Select).ToString(), ValueField = "id", TextField = "text" }).Style("width:200px")</td>
            </tr>*@
        <tr>
            <td class="addon">手机号</td>
            <td>@Html.TextBox(s => s.Mobile).Style("width:200px")</td>
        </tr>
        <tr>
            <td class="addon">邮件</td>
            <td>@Html.TextBox(s => s.Email).Style("width:200px")</td>
        </tr>
    </table>
</div>
<div data-options="region:'south',border:false" class="form-button">
    <a class="easyui-linkbutton" onclick="saveInfo()" id="btnSave" data-options="iconCls:'icon-save'">保存</a>
    <a class="easyui-linkbutton" onclick="saveInfo(true)" id="btnSaveAndNew" data-options="iconCls:'icon-save_new'">保存并新建</a>
    <a class="easyui-linkbutton" onclick="common.closeWindow()" id="btnClose" data-options="iconCls:'icon-cancel'">关闭</a>
</div>
